package daily.oct;

import java.util.Arrays;

public class lc2125 {
    /*
    思路比较简单。但是在更新数组（创建不含0的数组）处实现遇到了问题
     */
    public int numberOfBeams(String[] bank) {
        int total=0;
        int[] count=new int[bank.length];//用于存储每一行中“1”出现的数量
        for(int i=0;i<bank.length;i++){
            for(char c:bank[i].toCharArray()){
                if(c=='1'){
                    count[i]++;
                }
            }
        }

        //创建一个新数组，将旧数组中的所有0删去，便于后续计算
        int[] removeZero= Arrays.stream(count).filter(x->x!=0).toArray();
        for(int i=0;i<removeZero.length-1;i++){
            total+=removeZero[i]*removeZero[i+1];
        }
        return total;
    }

    public static void main(String[] args) {
        String[] bank1 = {"011001","000000","010100","001000"};
        String[] bank2 = {"000","111","000"};
        String[] bank3 = {"0","1"};

        lc2125 b = new lc2125();
        System.out.println(b.numberOfBeams(bank1));
        System.out.println(b.numberOfBeams(bank2));
        System.out.println(b.numberOfBeams(bank3));
    }
}
